from django.shortcuts import render,HttpResponse
import random
# Create your views here.
from utils.tencent.sms import send_sms_single
from tracer.settings import TENCENT_SMS_TEMPLATE


def send_sms(request):

    code = random.randrange(1000,9999)
    res = send_sms_single('13651400960',1181741,[code,])
    print(res)
    return HttpResponse(res)


from django import forms
from app01 import models
from django.core.validators import RegexValidator
from django.core.exceptions import ValidationError


class RegisterModelForm(forms.ModelForm):
    mobile_phone = forms.CharField(label='手机号',validators=[RegexValidator(r'^1[34578]\d{9}$'),'手机号格式错误'])
    password = forms.CharField(label='密码',widget=forms.PasswordInput())
    confirm_password = forms.CharField(label='重复输入', widget=forms.PasswordInput())
    code = forms.CharField(label='验证码')

    class Meta:
        model = models.UserInfo
        fields = ['username','eamil','password','confirm_password','mobile_phone','code']

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        for name,field in self.fields.items():
            field.widget.attrs.update({'class': 'form-control','placeholder':field.label})

def register(request):

    form = RegisterModelForm()
    return render(request, 'web/../web/templates/register.html', {'form':form})